home *** CD-ROM | disk | FTP | other *** search
/ Kit PC World De Ampliacion De Windows 95 / Kit PC World de ampliacion de Windows 95.iso / internet / sweeper / samples / olecon~1 / include / autoobj.h next >
C/C++ Source or Header  |  1995-11-25  |  7KB  |  149 lines

  1. //=--------------------------------------------------------------------------=
  2. // AutomationObject.H
  3. //=--------------------------------------------------------------------------=
  4. // Copyright  1995  Microsoft Corporation.  All Rights Reserved.
  5. //
  6. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF 
  7. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO 
  8. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A 
  9. // PARTICULAR PURPOSE.
  10. //=--------------------------------------------------------------------------=
  11. //
  12. // all of our objects will inherit from this class to share as much of the same
  13. // code as possible.  this super-class contains the unknown and dispatch
  14. // implementations for them.
  15. //
  16. #ifndef _AUTOMATIONOBJECT_H_
  17.  
  18. // all automation objects will use the Unknown object that supports aggegation.
  19. //
  20. #include "Unknown.H"
  21.  
  22. //=--------------------------------------------------------------------------=
  23. // the constants in this header file uniquely identify your automation objects.
  24. // make sure that for each object you have in the g_ObjectInfo table, you have
  25. // a constant in this header file.
  26. //
  27. #include "LocalSrv.H"
  28.  
  29. //=--------------------------------------------------------------------------=
  30. // AUTOMATIONOBJECTINFO
  31. //=--------------------------------------------------------------------------=
  32. // for each automation object type you wish to expose to the programmer/user
  33. // that is not a control, you must fill out one of these structures.  if the
  34. // object isn't CoCreatable, then the first four fields should be empty.
  35. // otherwise, they should be filled in with the appropriate information.
  36. // use the macro DEFINE_AUTOMATIONOBJECT to both declare and define your object.
  37. // make sure you have an entry in the global table of objects, g_ObjectInfo
  38. // in the main .Cpp file for your InProc server.
  39. //
  40. typedef struct tagAUTOMATIONOBJECTINFO {
  41.  
  42.     UNKNOWNOBJECTINFO unknowninfo;               // fill in with 0's if we're not CoCreatable
  43.     long         lVersion;                       // Version number of Object.  ONLY USE IF YOU'RE CoCreatable!
  44.     const IID   *riid;                           // object's type
  45.     LPSTR        pszHelpFile;                    // the helpfile for this automation object.
  46.     ITypeInfo   *pTypeInfo;                      // typeinfo for this object
  47.     UINT         cTypeInfo;                      // number of refs to the type info
  48.  
  49. } AUTOMATIONOBJECTINFO;
  50.  
  51. // macros to manipulate the AUTOMATIONOBJECTINFO in the global table table.
  52. //
  53. #define VERSIONOFOBJECT(index)         ((AUTOMATIONOBJECTINFO *)(g_ObjectInfo[(index)]).pInfo)->lVersion
  54. #define INTERFACEOFOBJECT(index)       *(((AUTOMATIONOBJECTINFO *)(g_ObjectInfo[(index)]).pInfo)->riid)
  55. #define PPTYPEINFOOFOBJECT(index)      &((((AUTOMATIONOBJECTINFO *)(g_ObjectInfo[(index)]).pInfo)->pTypeInfo))
  56. #define PTYPEINFOOFOBJECT(index)       ((AUTOMATIONOBJECTINFO *)(g_ObjectInfo[(index)]).pInfo)->pTypeInfo
  57. #define CTYPEINFOOFOBJECT(index)       ((AUTOMATIONOBJECTINFO *)(g_ObjectInfo[(index)]).pInfo)->cTypeInfo
  58. #define HELPFILEOFOBJECT(index)        ((AUTOMATIONOBJECTINFO *)(g_ObjectInfo[(index)]).pInfo)->pszHelpFile
  59.  
  60.  
  61. #ifndef INITOBJECTS
  62.  
  63. #define DEFINE_AUTOMATIONOBJECT(name, clsid, objname, fn, ver, riid, pszh) \
  64. extern AUTOMATIONOBJECTINFO name##Object \
  65.  
  66. #else
  67. #define DEFINE_AUTOMATIONOBJECT(name, clsid, objname, fn, ver, riid, pszh) \
  68.     AUTOMATIONOBJECTINFO name##Object = { { clsid, objname, fn }, ver, riid, pszh, NULL, 0} \
  69.  
  70. #endif // INITOBJECTS
  71.  
  72. //=--------------------------------------------------------------------------=
  73. // Standard Dispatch and SupportErrorInfo
  74. //=--------------------------------------------------------------------------=
  75. // all objects should declare these in their class definitions so that they
  76. // get standard implementations of IDispatch and ISupportErrorInfo.
  77. //
  78. #define DECLARE_STANDARD_DISPATCH() \
  79.     STDMETHOD(GetTypeInfoCount)(UINT *pctinfo) { \
  80.         return CAutomationObject::GetTypeInfoCount(pctinfo); \
  81.     } \
  82.     STDMETHOD(GetTypeInfo)(UINT itinfo, LCID lcid, ITypeInfo **ppTypeInfoOut) { \
  83.         return CAutomationObject::GetTypeInfo(itinfo, lcid, ppTypeInfoOut); \
  84.     } \
  85.     STDMETHOD(GetIDsOfNames)(REFIID riid, OLECHAR **rgszNames, UINT cnames, LCID lcid, DISPID *rgdispid) { \
  86.         return CAutomationObject::GetIDsOfNames(riid, rgszNames, cnames, lcid, rgdispid); \
  87.     } \
  88.     STDMETHOD(Invoke)(DISPID dispid, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pdispparams, VARIANT *pVarResult, EXCEPINFO *pexcepinfo, UINT *puArgErr) { \
  89.         return CAutomationObject::Invoke(dispid, riid, lcid, wFlags, pdispparams, pVarResult, pexcepinfo, puArgErr); \
  90.     } \
  91.  
  92.  
  93. #define DECLARE_STANDARD_SUPPORTERRORINFO() \
  94.     STDMETHOD(InterfaceSupportsErrorInfo)(REFIID riid) { \
  95.         return CAutomationObject::InterfaceSupportsErrorInfo(riid); \
  96.     } \
  97.  
  98.  
  99. //=--------------------------------------------------------------------------=
  100. // CAutomationObject
  101. //=--------------------------------------------------------------------------=
  102. // global class that all automation objects can inherit from to give them a
  103. // bunch of implementation for free, namely IDispatch and ISupportsErrorInfo
  104. //
  105. //
  106. class CAutomationObject : public CUnknownObject {
  107.  
  108.   public:
  109.     // aggreation query interface support
  110.     //
  111.     virtual HRESULT InternalQueryInterface(REFIID riid, void **ppvObjOut);
  112.  
  113.     // IDispatch methods
  114.     //
  115.     STDMETHOD(GetTypeInfoCount)(UINT *);
  116.     STDMETHOD(GetTypeInfo)(UINT, LCID, ITypeInfo **);
  117.     STDMETHOD(GetIDsOfNames)(REFIID, OLECHAR **, UINT, LCID, DISPID *);
  118.     STDMETHOD(Invoke)(DISPID, REFIID, LCID, WORD, DISPPARAMS *, VARIANT *, EXCEPINFO *, UINT *);
  119.  
  120.     //  ISupportErrorInfo methods
  121.     //
  122.     STDMETHOD(InterfaceSupportsErrorInfo)(REFIID);
  123.  
  124.     CAutomationObject(IUnknown *, int , void *);
  125.     virtual ~CAutomationObject();
  126.  
  127.     // callable functions -- things that most people will find useful.
  128.     //
  129.     virtual HINSTANCE GetResourceHandle(void);
  130.     HRESULT Exception(HRESULT hr, WORD idException, DWORD dwHelpContextID);
  131.  
  132.   protected:
  133.     // member variables that derived objects might need to get at information in the
  134.     // global object table
  135.     //
  136.     int   m_ObjectType;
  137.  
  138.   private:
  139.     // member variables we don't share.
  140.     //
  141.     BYTE  m_fLoadedTypeInfo;
  142. };
  143.  
  144.  
  145. #define _AUTOMATIONOBJECT_H_
  146. #endif // _AUTOMATIONOBJECT_H_
  147.  
  148.  
  149.